const rewire = require('rewire')
const webdriver = rewire('../common/webdriver.cjs')

const driverName = 'taobao'

async function main() {
    await initDriver()
    await webdriver.elemWaitUtilExist(driver, 
        '.member-login .member-delivery', 
        5*60*1000
    )
    await search()
}

async function initDriver() {
    const driver = await webdriver.createWebDriver(driverName)
    await webdriver.driverGoto(driver, "https://www.taobao.com")
}

async function search() {
    const driver = await webdriver.getWebDriver(driverName)
    const inputEl = await webdriver.elemFindItem(driver, '#q')
    await webdriver.elemInput(inputEl, '髋关节假体')

    const btnEl = await webdriver.elemFindItem(driver, '.btn-search.tb-bg')
    await webdriver.elemClick(btnEl)
    await webdriver.elemWaitUtilExist(driver, 
        '.mainsrp-itemlist .m-itemlist'
    )
    'UnusualStatus--wrap--kbi8ePx'
}

(async function() {
    const driver = await webdriver.getWebDriver(driverName)
    
    const btnEl = await webdriver.elemFindItem(driver, '.btn-search.tb-bg')
    await webdriver.elemClick(btnEl)
})()

search()


main()